package com.zahb.qadx.buriedpoint;

import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityEvent;

import com.google.gson.Gson;

import static com.zahb.qadx.buriedpoint.BuriedPoint.clickOnThe;

/**
 * AccessibilityDelegate实现类，完成埋点操作
 */

public class BuryingPointAccessibilityDelegate extends View.AccessibilityDelegate {
    @Override
    public void sendAccessibilityEvent(View host, int eventType) {
        super.sendAccessibilityEvent(host, eventType);
        //埋点
//        sendLog(host, eventType);
        clickOnThe(host, eventType);
    }

    private void sendLog(View host, int eventType) {
        String path="";
        if(eventType == AccessibilityEvent.TYPE_VIEW_CLICKED){
            ViewGroup mViewGroup = (ViewGroup) host.getParent();
            if (mViewGroup.getClass().toString().indexOf("DecorView")!=-1){

            }else {
                path=host.getClass().getName();//点击控件
                traverse(mViewGroup ,path);

            }
        }

    }

    private void traverse(ViewGroup host,String path){
        ViewGroup mViewGroup = (ViewGroup) host.getParent();
        if (mViewGroup.getClass().toString().indexOf("DecorView")!=-1){
            Log.d("路径", "path:="+    path);
        }else {
            path=path+"[0]"+mViewGroup.getClass().getName();
            traverse(mViewGroup,path);

        }


    }



}